<template>
  <div>
    <navmenu></navmenu>
    <el-container>
      <IndexMenu @indexSelect="listByCategory" ref="sideMenu"></IndexMenu>
      <el-main>
        <el-row>
          <el-col :span="8" v-for="(item, index) in lessons" :key="item.id" :offset="index > 0 ? 2 : 2" >
            <el-card :body-style="{ padding: '0px' }">
              <div style="padding: 14px;">
                <img :src="item.photo" class="image" style="width: 300px " height="100px">
                <p >课程：{{item.lessonname}} </p>
                <br>
                <div>
                  <el-button type="success" @click="gotocourse(item.id)" >查看详情</el-button>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>

      </el-main>

    </el-container>
  </div>
</template>

<script>
  import Navmenu from "./common/nav";
  import IndexMenu from "./IndexMenu";
  export default {
    name: "MyStudy",
    components: {IndexMenu, Navmenu},
    data() {
      return {
        showname:JSON.parse(window.sessionStorage.getItem('iflogin')), //判断登录
        loginname:window.sessionStorage.getItem('username'),
        lessons:[],

      }

    },
    created () {
    this.getLesson()
  },
    methods:{
       getLesson() {
      var _this = this
        this.$axios.get('/lessons').then(resp => {

            _this.lessons = resp.data
            console.log(1+_this.lessons.lessonname)

        })
        },
        listByCategory () {
        var _this = this
        var cid = this.$refs.sideMenu.cid
        console.log(cid)
        var url = 'categories/' + cid + '/lesson'
        this.$axios.get(url).then(resp => {
          console.log(1)
            _this.lessons = resp.data

        })
      },
      gotocourse(id){
       
          //指定跳转地址
           window.sessionStorage.setItem('id', id)
          this.$router.replace('/courseDetails')
        }

    }
  }
</script>

<style scoped>

</style>
